using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Rotate : MonoBehaviour
{
   
    public float Xangle = 0;
    public float Yangle = 10;
    public float Zangle = 0;
    public float scale = 2;
    // Start is called before the first frame update
    void Start()
    {
        
    }
    float CheckAngle(float value)
    {
        float angle = value - 180;
        if (angle > 0)
        {
            return angle - 180;
        }
        return angle + 180;
    }
    // Update is called once per frame
    void Update()
    {
        float delta = Time.deltaTime*scale;
        var euler = transform.eulerAngles;
        var angle = CheckAngle(euler.y);
        //限制在-60和60度之间
        if (angle <= -140 )
        {
            scale = Mathf.Abs(scale);
        }
        else if(angle > -20)
        {
            scale = -Mathf.Abs(scale);
        }

        

       
        transform.Rotate(Xangle, Yangle*delta, Zangle, Space.World);
    }
}
